var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
    value: !0
});
var o = e("NativeAdBase"),
i = cc._decorator,
a = i.ccclass,
r = i.property,
s = function(e) {
    __extends(t, e);
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        t.delay = 0;
        t.adNode = null;
        t.title = null;
        t.desc = null;
        t.mainSprite = null;
        t.closeBtn = null;
        t.extentBtns = [];
        t.extentBtnLables = [];
        t.nativeAd = null;
        t.curNativeData = null;
        return t
    }
    t.prototype.start = function() {
        var e = this;
        if (cc.sys.platform == cc.sys.HUAWEI_GAME) {
            this.adNode && (this.adNode.active = !1);
            for (var t = 0; t < this.extentBtns.length; t++) this.extentBtns[t].active = !1;
            setTimeout(function() {
                e.init()
            },
            1e3 * this.delay);
            var n = this;
            qg.onShow(function() {
                if (n.curNativeData && n.nativeAd) {
                    console.log("上报事件", n.curNativeData.adId);
                    n.nativeAd.reportAdShow({
                        adId: n.curNativeData.adId
                    })
                }
            })
        }
    };
    t.prototype.init = function() {
        this.nativeAd = qg.createNativeAd({
            adUnitId: Config.HUAWEI.nativeInsertId
        });
        this.nativeAd.setTagForChildProtection( - 1);
        this.nativeAd.setTagForUnderAgeOfPromise( - 1);
        this.nativeAd.setAdContentClassification("A");
        this.nativeAd.setNonPersonalizedAd(0);
        var e = this;
        this.scheduleOnce(function() {
            e.nativeAd.load()
        },
        .1);
        var t = "";
        this.nativeAd.onLoad(function(n) {
            try {
                n.adList.forEach(function(n) {
                    t = JSON.stringify(n);
                    e.curNativeData = JSON.parse(t)
                })
            } catch(e) {
                console.error("error", JSON.stringify(e))
            }
        });
        this.nativeAd.onError(function(e) {
            e && console.log("NativeUIAd: ", Config.HUAWEI.nativeInsertId, ", OnError", JSON.stringify(e))
        })
    };
    t.prototype.canShow = function() {
        return null != this.curNativeData
    };
    t.prototype.show = function(e) {
        void 0 === e && (e = !0);
        if (cc.sys.platform == cc.sys.HUAWEI_GAME) if (this.canShow()) {
            this.adNode && (this.adNode.active = !0);
            this.closeBtn && (this.closeBtn.active = !0);
            for (o = 0; o < this.extentBtns.length; o++) this.extentBtns[o].active = !0;
            this.title && (this.title.string = this.curNativeData.title);
            this.desc && (this.desc.string = this.curNativeData.source);
            for (o = 0; o < this.extentBtnLables.length; o++) this.curNativeData.clickBtnTxt && (this.extentBtnLables[o].string = this.curNativeData.clickBtnTxt);
            this.mainSprite && (this.curNativeData.imgUrlList && this.curNativeData.imgUrlList.length > 0 ? SDK.Util.Helper.loadImage(this.mainSprite, this.curNativeData.imgUrlList[0]) : this.curNativeData.icon && SDK.Util.Helper.loadImage(this.mainSprite, this.curNativeData.icon));
            console.log("上报事件", this.curNativeData.adId);
            this.nativeAd.reportAdShow({
                adId: this.curNativeData.adId
            })
        } else {
            if (e) {
                var t = this,
                n = function() {
                    if (t.canShow()) {
                        t.unschedule(n);
                        t.show()
                    }
                };
                this.schedule(n, .1, 30)
            }
            for (var o = 0; o < this.extentBtns.length; o++) this.extentBtns[o].active = !1;
            this.closeBtn && (this.closeBtn.active = !1)
        }
    };
    t.prototype.click = function() {
        if (cc.sys.platform == cc.sys.HUAWEI_GAME) {
            this.nativeAd && this.curNativeData && this.nativeAd.reportAdClick({
                adId: this.curNativeData.adId
            });
            this.close()
        }
    };
    t.prototype.close = function() {
        cc.sys.platform == cc.sys.HUAWEI_GAME && this.node && this.node.isValid && this.node.destroy()
    };
    __decorate([r(cc.Float)], t.prototype, "delay", void 0);
    __decorate([r(cc.Node)], t.prototype, "adNode", void 0);
    __decorate([r(cc.Label)], t.prototype, "title", void 0);
    __decorate([r(cc.Label)], t.prototype, "desc", void 0);
    __decorate([r(cc.Sprite)], t.prototype, "mainSprite", void 0);
    __decorate([r(cc.Node)], t.prototype, "closeBtn", void 0);
    __decorate([r([cc.Node])], t.prototype, "extentBtns", void 0);
    __decorate([r([cc.Label])], t.prototype, "extentBtnLables", void 0);
    return __decorate([a], t)
} (o.default);
n.default = s